/*

This file is part of Rooms3D.

Copyright (C) 2008 Pixecur Technologies Incorporated (Esotera).
Visit Esotera at http://www.esoteras3.com
 
Rooms3D is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
 
Rooms3D is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with Rooms3D; see the file COPYING.  If not, write to 
Pixecur Technologies, 213-31 Peet Street, St. John's, NL, A1B 3W8. 
 
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
 
*/

package com.datasentinel.j3d.controls;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.RestrictedAccessException;

public abstract class J3DComponentUI
{
	/**
	 * Container
	 */
	protected BranchGroup baseBrnchGrp;
	
	public J3DComponentUI()
	{
		initializeComponentGUI();
	}
	
	/**
	 * Instantiate and initialize components comprising this control
	 */
	protected void initializeComponentGUI()
	{
		this.baseBrnchGrp = new BranchGroup();
		initializeComponentParts();
		initializeComponentPartsLayout();
		constructComponentGUIBranch();
	}
	
	/**
	 * Construct and initialize 3D component parts (e.g. shapes, appearances etc) and their
	 * properties.  
	 */
	protected abstract void initializeComponentParts();
	/**
	 * Initialize arrangement and internal transformations of varios parts, comprising this
	 * 3D component
	 */
	protected abstract void initializeComponentPartsLayout();
	/**
	 * Construction of the local branch of the Scene Graph
	 */
	protected abstract void constructComponentGUIBranch();
	
	/**
	 * Addition of the other controls, that should be shown in 
	 * the scene graph branch of this component.
	 */
	public void augmentComponentGUIBranch(J3DComponent component)
	{
		
	}

	/**
	 * Calls overriden render3DComponent() method to performs the necessary adjustments to 
	 * show the visual representation conforming to the model values and adds the 
	 * rendered branch to the component BranchGroup 
	 */
	public void render3DComponentUI(J3DComponent j3dComponent)
	{
		render3DComponent(j3dComponent);
		
		try 
		{
			if(baseBrnchGrp.getParent() != j3dComponent)
			{
				j3dComponent.addChild(baseBrnchGrp);
			}
		} catch (RestrictedAccessException e) 
		{
			Logger.getLogger(getClass().getName()).log(Level.WARNING, "error rendering: " + e.getMessage());
		}
	}
	
	/**
	 * Performs the necessary adjustments to show the visual representation conforming
	 * to the model values.  
	 */
	public abstract void render3DComponent(J3DComponent j3dComponent);
}
